﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace CNDM.UserControls.Detail
{
    public partial class ucDetail : System.Web.UI.UserControl
    {
        private string news_id = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["news_id"] != null && Request.QueryString["news_id"].ToString() != "")
            {
                news_id = Request.QueryString["news_id"].ToString();
            }

            

            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            DataTable dt = new DataTable();
            dt = BO.News.NewsData.Get_NewsDetail(Convert.ToInt64(news_id));
            if (dt != null && dt.Rows.Count > 0)
            {
                ltrContent.Text = dt.Rows[0]["News_Content"].ToString();
                ltrNewsInitContent.Text = dt.Rows[0]["News_InitContent"].ToString();
                ltrNewsPublished.Text = dt.Rows[0]["News_PublishDate"].ToString();
                ltrNewsTitle.Text = dt.Rows[0]["News_title"].ToString();

                if (dt.Rows[0]["news_image"].ToString() != "")
                {
                    imgDetail.ImageUrl = dt.Rows[0]["Image_Url"].ToString();
                    imgDetail.Visible = true;
                }
                else
                {
                    imgDetail.Visible = false;
                }

                SetPageTitle(dt.Rows[0]["News_InitContent"].ToString(), dt.Rows[0]["News_title"].ToString());
            }

        }

        private void SetPageTitle(string desc, string title)
        {
            var page = (Page)HttpContext.Current.Handler;
            page.Title = title + " - Cẩm nang điện máy";
            page.MetaDescription = desc + " - Cẩm nang điện máy";
            page.MetaKeywords = desc + ",cẩm nang điện máy";
        }
    }
}